-- Copyright (c) Huoty, All rights reserved
-- Author: Huoty <sudohuoty@gmail.com>
-- CreateTime: 2019-05-26 10:10:20

t = {
    a = 1,
    __index = function (_t, name)
        return "hello"
    end
}

print(t.a)
print(t.b)

setmetatable(t, t)
print(t.b)
print(getmetatable(t))


t.__metatable = "error, operating not permit"
print(getmetatable(t))
print(t.c)
-- setmetatable(t, {})
print("----------\n")


local mt = {
    __index = function (t, name)
        return "None"
    end
}
print(string.format("mt id: %s", mt))

local tbl = { a = 1 }
print(string.format("tbl id: %s", tbl))
print(tbl.a)
print(tbl.b)

setmetatable(tbl, mt)
print(string.format("tbl metatable: %s", getmetatable(tbl)))
print(tbl.b, tbl.c)

mt.__metatable = "error, cannot get the metatable"
print(getmetatable(tbl))
print(tbl.d, tbl.e)
setmetatable(tbl)
